/*
 * @Description: 用户服务
 * @Author: chenjiaxin
 * @Date: 2021-12-21 21:35:34
 * @LastEditTime: 2021-12-26 19:09:46
 * @FilePath: \novel-serve\src\service\user.service.js
 */
const connection = require('../app/database');

class UserService {
  async getUserByEmail (e_mail) {
    try {
      const statement = `SELECT * FROM user WHERE e_mail = ?;`;
      const [result] = await connection.execute(statement, [e_mail]);
      return result[0];
    } catch (error) {
      console.log(error);
    }
    
  }

  async createUser (user) {
    
    try {
      let { e_mail, password } = user;
      // console.log(user,e_mail, password);
      // console.log(connection.execute);
      //                  INSERT INTO user (e_mail, password) VALUES ('1839479647@qq.com', '11111');
      // const statement = `INSERT INTO user (e_mail, password) VALUES ('717255820@qq.com', '123456');`;
      // const statement = `insert into user (e_mail, password) values ('14717255820@qq.com', '123456');`;
      const statement = `INSERT INTO user (e_mail, password) VALUES (?, ?);`;
      const result = await connection.execute(statement, [e_mail, password]);

      // const statement = `SELECT * FROM user WHERE e_mail = 11;`;
      // const [ result ] = await connection.execute(statement);
      // console.log("入库成功", result);
      return result[0];
    } catch (error) {
      console.log(error);
    }
    
    
  }
}

module.exports = new UserService();
